
function [ ] = test_plots()

suffix = '';

plots('a500', 'led filter on', suffix);
plots('a500', 'led filter off', suffix);
plots('a1200', 'led filter on', suffix);
plots('a1200', 'led filter off', suffix);
plots('a1200', 'unfiltered', suffix);

winuae_plots();

end

function [ ] = plots( amiga_model, audio_filter_mode, suffix )

plots1(amiga_model, audio_filter_mode, suffix, 'math direct');
plots1(amiga_model, audio_filter_mode, suffix, 'math fq');
plots1(amiga_model, audio_filter_mode, suffix, 'math ts');
plots1(amiga_model, audio_filter_mode, suffix, 'math lsim');
plots1(amiga_model, audio_filter_mode, suffix, 'spice fq');

end

function [ ] = plots1( amiga_model, audio_filter_mode, suffix, method )

fs = get_sampling_fq();

blip1 = get_blip(amiga_model, audio_filter_mode, method, 'none');
blip2 = get_blip(amiga_model, audio_filter_mode, method, 'conv');
blip3 = get_blip(amiga_model, audio_filter_mode, method, 'fq');
if strcmpi(method, 'math lsim')
    blip4 = get_blip(amiga_model, audio_filter_mode, method, 'lsim');
end

[wblip, t] = get_blip(amiga_model, audio_filter_mode, 'winuae');

FS = get_spice_fq(amiga_model, audio_filter_mode);
FS = abs(FS);
FS = [FS(1:1:22050), zeros(1, 30000 - 22050)];

blep1 = get_blep(blip1);
blep2 = get_blep(blip2);
blep3 = get_blep(blip3);
if strcmpi(method, 'math lsim')
    blep4 = get_blep(blip4);
end
wblep = get_blep(wblip);

F1 = abs(fft(blip1, fs));
F2 = abs(fft(blip2, fs));
F3 = abs(fft(blip3, fs));
if strcmpi(method, 'math lsim')
    F4 = abs(fft(blip4, fs));
end
FW = abs(fft(wblip, fs));

F1 = F1(1:1:30000);
F2 = F2(1:1:30000);
F3 = F3(1:1:30000);
if strcmpi(method, 'math lsim')
    F4 = F4(1:1:30000);
end
FW = FW(1:1:30000);

fx = linspace(0, 30000, 30000);

name = sprintf('blip fq log ''%s'' ''%s'' ''%s'' %s', ...
   amiga_model, audio_filter_mode, method, suffix);
fig = figure;
set(fig,'units','normalized','outerposition',[0 0 1 1]);
hold on;
plot(log(fx), 20*log(FS), '.');
plot(log(fx), 20*log(F1), 'r');
plot(log(fx), 20*log(F2), 'g+');
plot(log(fx), 20*log(F3), 'co');
if strcmpi(method, 'math lsim')
    plot(log(fx), 20*log(F4), 'mx');
end
plot(log(fx), 20*log(FW), 'b');
if strcmpi(method, 'math lsim')
    legend('spice fq', 'none', 'conv', 'fq', 'lsim', 'winuae');
else
    legend('spice fq', 'none', 'conv', 'fq', 'winuae');
end
title(name);
saveas(gcf, strcat('plots/' , name, '.png'));
close(fig);

name = sprintf('blip fq lin ''%s'' ''%s'' ''%s'' %s', ...
   amiga_model, audio_filter_mode, method, suffix);
fig = figure;
set(fig,'units','normalized','outerposition',[0 0 1 1]);
hold on;
plot(fx, FS, '.');
plot(fx, F1, 'r');
plot(fx, F2, 'g+');
plot(fx, F3, 'co');
if strcmpi(method, 'math lsim')
    plot(fx, F4, 'mx');
end
plot(fx, FW, 'b');
if strcmpi(method, 'math lsim')
    legend('spice fq', 'none', 'conv', 'fq', 'lsim', 'winuae');
else
    legend('spice fq', 'none', 'conv', 'fq', 'winuae');
end
title(name);
saveas(gcf, strcat('plots/' , name, '.png'));
close(fig);

name = sprintf('blip time ''%s'' ''%s'' ''%s'' %s', ...
   amiga_model, audio_filter_mode, method, suffix);
fig = figure;
set(fig,'units','normalized','outerposition',[0 0 1 1]);
hold on;
plot(t, blip1, 'r');
plot(t, blip2, 'g+');
plot(t, blip3, 'co');
if strcmpi(method, 'math lsim')
    plot(t, blip4, 'mx');
end
plot(t, wblip, 'b');
if strcmpi(method, 'math lsim')
    legend('none', 'conv', 'fq', 'lsim', 'winuae');
else
    legend('none', 'conv', 'fq', 'winuae');
end
title(name);
saveas(gcf, strcat('plots/' , name, '.png'));
close(fig);

name = sprintf('blep time ''%s'' ''%s'' ''%s'' %s', ...
   amiga_model, audio_filter_mode, method, suffix);
fig = figure;
set(fig,'units','normalized','outerposition',[0 0 1 1]);
hold on;
plot(t, blep1, 'r');
plot(t, blep2, 'g+');
plot(t, blep3, 'co');
if strcmpi(method, 'math lsim')
    plot(t, blep4, 'mx');
end
plot(t, wblep, 'b');
if strcmpi(method, 'math lsim')
    legend('none', 'conv', 'fq', 'lsim', 'winuae');
else
    legend('none', 'conv', 'fq', 'winuae');
end
title(name);
saveas(gcf, strcat('plots/' , name, '.png'));
close(fig);

end

function [] = winuae_plots()

fs = get_sampling_fq();

blip1 = get_blip('a500', 'led filter off', 'winuae');
blip2 = get_blip('a500', 'led filter on', 'winuae');
blip3 = get_blip('a1200', 'led filter off', 'winuae');
blip4 = get_blip('a1200', 'led filter on', 'winuae');
[blip5, t] = get_blip('a1200', 'unfiltered', 'winuae');

blep1 = step_calc(blip1);
blep2 = step_calc(blip2);
blep3 = step_calc(blip3);
blep4 = step_calc(blip4);
blep5 = step_calc(blip5);

F1 = abs(fft(blip1, fs));
F2 = abs(fft(blip2, fs));
F3 = abs(fft(blip3, fs));
F4 = abs(fft(blip4, fs));
F5 = abs(fft(blip5, fs));
F1 = F1(1:1:30000);
F2 = F2(1:1:30000);
F3 = F3(1:1:30000);
F4 = F4(1:1:30000);
F5 = F5(1:1:30000);
fx = (1:1:30000);

fig = figure;
set(fig,'units','normalized','outerposition',[0 0 1 1]);
hold on;
plot(t, blep1, 'r');
plot(t, blep2, 'g');
plot(t, blep3, 'b');
plot(t, blep4, 'c');
plot(t, blep5, 'm');
legend('a500off', 'a500on', 'a1200off', 'a1200on', 'unfiltered');
title('winuae bleps');
saveas(gcf, strcat('plots/winuae bleps.png'));
close(fig);

fig = figure;
set(fig,'units','normalized','outerposition',[0 0 1 1]);
hold on;
plot(t, blip1, 'r');
plot(t, blip2, 'g');
plot(t, blip3, 'b');
plot(t, blip4, 'c');
plot(t, blip5, 'm');
legend('a500off', 'a500on', 'a1200off', 'a1200on', 'unfiltered');
title('winuae blips');
saveas(gcf, strcat('plots/winuae blips.png'));
close(fig);

fig = figure;
set(fig,'units','normalized','outerposition',[0 0 1 1]);
hold on;
plot(fx, F1, 'r');
plot(fx, F2, 'g');
plot(fx, F3, 'b');
plot(fx, F4, 'c');
plot(fx, F5, 'm');
legend('a500off', 'a500on', 'a1200off', 'a1200on', 'unfiltered');
title('winuae fq lin');
saveas(gcf, strcat('plots/winuae fq lin.png'));
close(fig);

fig = figure;
set(fig,'units','normalized','outerposition',[0 0 1 1]);
hold on;
plot(log(fx), 20*log10(F1), 'r');
plot(log(fx), 20*log10(F2), 'g');
plot(log(fx), 20*log10(F3), 'b');
plot(log(fx), 20*log10(F4), 'c');
plot(log(fx), 20*log10(F5), 'm');
legend('a500off', 'a500on', 'a1200off', 'a1200on', 'unfiltered');
title('winuae fq log');
saveas(gcf, strcat('plots/winuae fq log.png'));
close(fig);

end